import request from '../util/request';
import { message } from 'antd';

export default {
    namespace: 'book-select',
    state: {
        bookList: [],
        searchText:'',
        value:undefined,
    },
    effects: {
        *queryList({payload}, sagaEffects) {
            debugger;
            const { call, put } = sagaEffects;
            const endPointURI = '/dev/bookList?searchText='+(payload?payload.searchText:'');
            try { // 加入 try catch 捕获抛错
                const bookList = yield call(request, endPointURI)
                yield put({ type: 'loadData', payload: bookList });
              } catch (e) {
                message.error('数据获取失败'); // 打印错误信息
              }
        }
    },
    reducers: {
        loadData(state, { payload: bookList }) {
            return {
                ...state,
                bookList
            }
        },
        updateState(state, { payload}) {
            debugger;
            return {
                ...state,
                ...payload
            }
        }
    }
};